#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include<string.h> 

void write_log(char *w_file_name,char *w_now_time,char *w_note){
	FILE *fp = NULL;
	fp = fopen(w_file_name,"a+");
	
	if(NULL == fp)
	{
		printf("fail to fopen\n");
		return;
	}
	fwrite(w_now_time,strlen(w_now_time),1,fp);
	fwrite(" ",1,1,fp);
	fwrite(w_note,strlen(w_note),1,fp);
	fwrite("\n",1,1,fp);
	fclose(fp);
	printf("write success\n");

}
int main(int argc, char const *argv[])
{
	time_t now;
    struct tm * pTM;
    char file_name[12]={0};
    char old_file[12]={0};
    char now_time[12]={0};
    char note[128]={0};
    time(&now);
    pTM = localtime(&now);
    sprintf(file_name, "%04d%02d%02d.txt",
            pTM->tm_year+1900, pTM->tm_mon+1, pTM->tm_mday);
    
    sprintf(now_time, "%04d%02d%02d",
            pTM->tm_year+1900, pTM->tm_mon+1, pTM->tm_mday);
    sprintf(note,"测试测试测试测试测试测试");

	write_log(file_name,now_time,note);
	
	sprintf(old_file, "%04d%02d%02d.txt",
            pTM->tm_year+1900, pTM->tm_mon+1, pTM->tm_mday - 3);
	remove(old_file);
	return 0;
}